package com.example.software.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.software.entity.ApplyEntity;
import com.example.software.result.PageResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.software.utils.PageUtils;
import com.example.software.utils.Query;

import com.example.software.dao.RecodeDao;
import com.example.software.entity.RecodeEntity;
import com.example.software.service.RecodeService;


@Service("recodeService")
public class RecodeServiceImpl extends ServiceImpl<RecodeDao, RecodeEntity> implements RecodeService {

    @Autowired
    private RecodeDao recodeDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        LambdaQueryWrapper<RecodeEntity> wrapper = new LambdaQueryWrapper<>();

        if (params.containsKey("doctorId")) {

            Long doctorId = (Long) params.get("doctorId");
            System.out.println("doctorId"+doctorId);
            wrapper.eq(doctorId != null, RecodeEntity::getDoctorId, doctorId);

        }
        if (params.containsKey("state")) {
            Integer state = (Integer) params.get("state");
            wrapper.eq(state != null, RecodeEntity::getState, state);
        }
//        if (params.containsKey("name")) {
//            String name = (String) params.get("name");
//            wrapper.like(StringUtils.isNotBlank(name), RecodeEntity::get, name);
//        }

//        wrapper.eq(RecodeEntity::getState,4);   //查询出全部已线下核销的记录（排队状态）

//        IPage<RecodeEntity> page = this.page(
//                new Query<RecodeEntity>().getPage(params),
//                wrapper
//        );

        Page<RecodeEntity> page = new Page<>((Long) params.get("page"), (Long) params.get("limit"));

//        IPage<RecodeEntity> page = recodeDao.selectRecodePage(page2,);

        return new PageUtils(page);
    }

    @Override
    public List<RecodeEntity> getByDoctorId(Long doctorId) {

        List<RecodeEntity> list = recodeDao.getByDoctorId(doctorId);

        return list;

    }

    @Override
    public PageUtils queryPage2(String page, String size, Long doctorId, Integer state, String name) {


        Page<RecodeEntity> page2 = new Page<>(Long.parseLong(page), Long.parseLong(size));
        IPage<RecodeEntity> page3 = recodeDao.selectRecodePage(page2, doctorId,state,name);

        return new PageUtils(page3);
    }


}